#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_mcdbterm.info <<'%EOF%'
   cc_rsp_mcdbterm
   ---------------
   Molecule:         H3+ in C2v
   Wave Function:    CCSD (FCI) / STO-3G
   Test Purpose:     B-term (components) of Magnetic circular dichroism
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_mcdbterm.mol <<'%EOF%'
BASIS
STO-3G
B term (MCD) components of H3+

    2  1 2  X  Z      1.00D-12
        1.0   1
HC     0.000000          -0.224905893        0.000000
        1.0   1
HL     1.000000           0.899623572        0.000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_mcdbterm.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.ANGMOM
.GAUGEO
 0.0 0.0 0.0
**WAVE FUNCTIONS
.CC
*SCF INPUT
.THRESH
  1.0d-12
*CC INPUT
.CCSD
.THRENR
 1.0d-9
.THRLEQ
 1.0d-9
*CCEXCI
.NCCEXCI
 2 2 0 0
.THREXC
 1.0d-9
*CCMCD
.MCD
**END OF DALTON INPUT
%EOF%

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_mcdbterm.check
cat >>cc_rsp_mcdbterm.check <<'%EOF%'
log=$1
#
if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy: * \-1\.225131947[0-9]" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * \-1\.242129615[0-9]" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * \-1\.2492926" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=6
ERROR[1]="SCF, MP2 OR CCSD ENERGY NOT CORRECT"
#
# CCSD (unrelaxed) MCD-Bterm components:
CRIT1=`$GREP "For transition \|o> \-> \|f\(  (0| )\.74812\)>, of symm\. 2" $log | wc -l`
CRIT2=`$GREP "B term contribution \(au\)\: * \-1\.161889(39|40|41|42) \(antisym\)" $log | wc -l`
#
CRIT3=`$GREP "For transition \|o> \-> \|f\(  1\.67467\)>, of symm\. 2" $log | wc -l`
CRIT4=`$GREP "B term contribution \(au\)\: * (\-|\-0)\.0145800[4-6] \(antisym\)" $log | wc -l`
#
CRIT5=`$GREP "For transition \|o> \-> \|f\(  1\.00344\)>, of symm\. 1" $log | wc -l`
CRIT6=`$GREP "B term contribution \(au\)\: * \-1\.0028638[6-8] \(antisym\)" $log | wc -l`
#
CRIT7=`$GREP "For transition \|o> \-> \|f\(  1\.44694\)>, of symm\. 1" $log | wc -l`
CRIT8=`$GREP "B term contribution \(au\)\: * (\-|\-0)\.1964734.* \(antisym\)" $log | wc -l`
#
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8`  
CTRL[2]=8
ERROR[2]="CCSD (UNRELAXED) MCD-Bterm COMPONENTS NOT CORRECT"
#
PASSED=1
for i in 1 2
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done
#
if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
